#ifndef COMPUTER_HPP_
#define COMPUTER_HPP_
/*******************************************************************************
 ** Name: computer.hpp                                                        **
 ** Description:              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2011  Barry Gian James <gian@gamingods.net>            **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL: https://govtsanct.svn.codeplex.com/svn/trunk/lib/computer.hpp $
 ******************************************************************************/

// $Id: computer.hpp 63608 2011-11-24 07:07:02Z unknown $
// Last Modified by $Author: unknown $

#include "item.hpp"


enum class OperatingSystemType : unsigned short
{
	Unknown,
	Standard = 0x01,
	Advanced = 0x02,
	NeuralNet = 0x04,
	Hyperthreading = 0x08,
	Distributed = 0x10,
	Polymorphic = 0x20
};

enum class SoftwareType : ushort
{
	Offensive, Defensive, Utility, OS, Game, Networking
};

// This is a list of all the types of software programs that can be written,
// owned, and ran.
enum class SoftwareProgramType : unsigned int
{
	Unknown = 0x0000000000000000,
	Anchor = 0x0000000000000001,			// used by intruder to keep from getting booted
	Boot = 0x0000000000000002,			// used by admin to boot intruder from computer
	Flood = 0x0000000000000004, 			// used to temp disconnect a remote host from network
	Sinflut = 0x0000000000000008,		// same as Flood but causes one random program to stop working temporarily
	Jupe = 0x0000000000000010,			// used to block a disconnected remote host from connecting locally
	PortScan = 0x0000000000000020, 		// detects firewalls, services
	Snare = 0x0000000000000040, 			// used by admin to keep intruder from logging off
	Release = 0x0000000000000080,		// used by intruder to release network socket or terminal and log off
	Decoy = 0x0000000000000100, 			// used by intruder to slow a trace
	BoobyTrap_V1 = 0x0000000000000200, 	// executed on failed firewall hack, removes intruder programs
	BoobyTrap_V15 = 0x0000000000000400,
	BoobyTrap_V2 = 0x0000000000000800,
	BoobyTrap_V3 = 0x0000000000001000,	// similar to above, but unleases a Virus_V1 on intruder terminal
	Fork = 0x0000000000002000, 			// forks extra process to run apps, gives 1 extra move per turn
	AntiVirus = 0x0000000000004000,		// operates against worms, viruses, trojans, malware
	AntiVirusEnterprise = 0x0000000000008000, // same ass AntiVirus but operates across the whole network
	CP = 0x0000000000010000,				// used to make copies of other programs on the local computer
	FSCK = 0x0000000000020000,			// will repair damaged program slots
	KeyGen_V1 = 0x0000000000040000,		// onboard encryption key generator to bypass encryption. Otherwise, if downloaded will be encrypted and require a skillcheck to decrypt.
	KeyGen_V15 = 0x0000000000080000,		// same as V1 but works on 128-bit encryption
	KeyGen_V2 = 0x0000000000100000,		// same as v1.5 but works on 1024-bit encryption
	KeyGen_V3 = 0x0000000000200000,		// same as v2 but works on 4096-bit encryption
	CRCError = 0x0000000000400000,		// will fragment/damage program slots
	RM =       0x0000000000800000,				// will remove programs from a computer
	Transfer = 0x0000000001000000,		// will transfer files from local computer to an attached device
	SCP =      0x0000000002000000,			// will download files from a remote computer to local computer
	GPG_V1 =   0x0000000004000000,			// will encrypt files with 64-bit encryption
	GPG_V15 =  0x0000000008000000,		// will encrypt files with 128-bit encryption
	GPG_V2 =   0x0000000010000000,			// 1024-bit encryption
	GPG_V3 =   0x0000000020000000,			// 4096-bit encryption
	Debugger = 0x0000000040000000,		// reveals any/all problems affecting a program
	LS =          0x0000000080000000,				// list all files on the local terminal/computer
	ResourceHog = 0x0000000100000000,	// negates Fork. Only allows Move-action actions for d6 rounds
	HideProc_V1 = 0x0000000200000000,	// will hide intruder processes making it more difficult to detect
	HideProc_V2 = 0x0000000400000000,	// same as v1 but hides more processes at one time
	PIDSearch =   0x0000000800000000,		// works against HideProc by searching all known Process IDs (PID)
	TCPIP_Stack = 0x0000001000000000,	// program to provide IPv4 and IPv6 connectivity to network
	CodeBloat_V1 = 0x0000020000000000,	// takes up d4 random program slots on terminal
	CodeBloat_V2 = 0x0000040000000000,	// same as v1 but consumes d4+2 program slots
	CodeBloat_V3 = 0x0000080000000000,	// same as v2 but consomes d6 program slots as long as its active
	DeviceInfo =   0x0000100000000000,		// lists the #cpus, type of OS, #program slots, #ram, etc on running terminal
	DeviceInfo_Net = 0x0020000000000000,	// same as DeviceInfo but saves terminal info from remote terminal to local
	PortRedirect = 0x0000400000000000,	// will redirect any attacks to system back on instigating system
	KeyLogger =    0x0000800000000000,		// this program will log any keystrokes used on the terminal its running on and relay info back (reduces accessDC)
	NAT =          0x0001000000000000,			// this program protects against any program attempting to get its IP address
	TraceRoute =   0x0002000000000000,		// attempts to trace back to location of intruder terminal
	Virus_V1 =     0x0004000000000000,		// causes corruption and loss of 1 random program
	Virus_V15 =    0x0008000000000000,		// causes corruption and loss of 2 random programs
	Virus_V2 =     0x0010000000000000,		// causes the corruption and loss of d4 random programs
	Worm_V1 =      0x0020000000000000,		// causes loss of 1 program on local terminal, then spreads to any connected terminals
	AppArmor =     0x0040000000000000,		// detects if a program or file has been modified and silently alarms
	Find =         0x0080000000000000,			// attempts to find a file or program that matches the given description
	InodeDup =     0x0100000000000000,		// program duplicates file inode to make it more difficult to find (DC+15)
	Alias =              0x0200000000000000,			// renames any existing programs to a name of your choosing, hiding the nature of the program
	BootSectorVirus_V1 = 0x0400000000000000,	// hides in boot sector and corrupts 1 program slot every 2 rounds until stopped
	BootSectorVirus_V15 =0x0800000000000000, // same, but corrupts 2 program slots every 2 rounds until stopped
	Inoculation =        0x1000000000000000,	// the nemesis of BootSectorVirus; removes any infection of BootSectorVirus_V*
	SelfModifyingCode =  0x2000000000000000,	// injects junk code into terminal programs causing use of the program to act like BETA or Shareware
	VirusSignatureDB =   0x4000000000000000,	// detects and stops presence of Worm_V1 and Virus_V1*
	Cat				=    0x8000000000000000		// displays the contents ofa  file to the screen
};



//! @struct OperatingSystem
//! @brief Basic representation of the OS
#pragma db object table("computer_os")
struct OperatingSystem
{
	OperatingSystemType	type;
	unsigned int		support;
	int					cost;
	ItemRestriction		license;

};

// Code/Software upgrade flags
#define CODE_DMG_UPGRADE	0x0001	// upgrades any dmg this program causes
#define CODE_FILE_LOCK		0x0002	// impossible to open file
#define CODE_HIDDEN		0x0004	// increases DC to find this file
#define CODE_OPTIMIZED		0x0008	// takes up fewer slots
#define CODE_GARBAGE_COLLECTION 0x0010 // reduces needed ram to run
#define CODE_BIN_COMPAT_STD 0x0020
#define CODE_BIN_COMPAT_ADV 0x0040
#define CODE_BIN_COMPAT_NN	 0x0080
#define CODE_BIN_COMPAT_HYP 0x0100
#define CODE_BIN_COMPAT_DIST 0x0200
#define CODE_BIN_COMPAT_POLY 0x0400
#define CODE_BIN_BYTE_CODE 0x0800	// operates on all OS's
#define CODE_MULTI_THREADED 0x1000	// 1 extra action per turn

class Software;
//! @class Computer
//! @brief The computer class
#pragma db object table("computers")
class Computer : public Item
{
public:

private:
	friend class odb::access;
	std::string			hostname;
	OperatingSystem		os;
	ushort				program_slots;
	ushort				memory;		// in Gb
	ushort				cpu;		// number of cpu's
	unsigned int		supported_os;
	unsigned int		supported_sw;	// supported software flags
	ushort				access_dc;	// DC of hacking the terminal
	ushort				firewall_dc;	// dc of hacking from the network
	unsigned int		upgrades;
	ushort				bonus;		// to ComputerUse skill
	std::vector<boost::shared_ptr<Software> > software;
	std::vector<boost::shared_ptr<Computer> > network;
	std::string			ip;		// this could be removed.
};

enum class SoftwareCategory
{
	Unknown,
	Commercial, OpenSource, Shareware, Beta
};

//! @class Code
//! @brief The base class for all software
#pragma db object table("computer_code")
class Software : public Item
{
public:

private:
	friend class odb::access;

	SoftwareType	sw_type;
	ushort			min_ram;
	unsigned int	supported_os;
	ushort			size;	// in program_slots
	std::string		version;
	SoftwareCategory category;
	SoftwareProgramType	program;
	std::string		source;		// falcon script source
	ushort			pr;		// power rating
};



#endif /* COMPUTER_HPP_ */
